<template>
	<view id="names">
		<view class="ibody">
			<view class="top">
				<view class="banner" style="height: 200px;">
					<h1>企业纳税信息</h1>
				</view>
				<view class="form">
					<view class="input" style="display: flex;align-items: center;">
						<label>您的电话</label>
						<input v-model="mobile" style="width: 50%;display: inline-block;" focus placeholder="请输入电话" />
					</view>
					<view class="input" style="display: flex;align-items: center;">
						<label>验证码</label>
						<input style="width: 50%;" v-model="code" placeholder="请输入手机验证码">
						<uni-tag @click="getCode" :text="verifyCode.verifyCodeTips" type="primary" />
						</input>
					</view>
					<view class="submit">
						<button style="padding: 8px;" @click="submit()" type="primary" shape="round">立即查询</button>
					</view>
					<view class="radio" style="text-align: center;">
						<checkbox-group @change="xz=!xz">
							<checkbox :checked="xz">我已阅读同意
								<span @click="serveAgreeVisible=true" style="color: #375FE8;">《服务协议》</span>
							</checkbox>
						</checkbox-group>
					</view>
					<view style="margin: 10px 5px 20px">
						<view @click="$tab.navigateTo('/pages/com')" style="float: left;margin-left: 20px;">示例报告
						</view>
						<view @click="$tab.navigateTo('/pages/record')"
							style="float: right;display: inline-block;margin-right: 20px;">历史查询</view>
					</view>
				</view>
			</view>

			<view class="shuoming">
				<view class="text-center bq">成都天启数科网络安全技术有限公司 版权所有</view>
				<view class="text-center">
					"容易查"严格按照相关法律法规及监管单位的操作要求，合法合规经营，所有报告数据均由第三方合规公司、机构提供，不获取用户本地隐私数据，若您对查询数据结果有异议，可联系客服发起异议处理。</view>
			</view>
			<view class="fc">
				<view class="circular" @click="$tab.navigateTo('/pages/help')">帮助</view>
			</view>
		</view>
		<serveAgree v-if="serveAgreeVisible" @readed="serveAgreeVisible=false" />
	</view>
</template>
<script>
	import serveAgree from '@/components/serveAgree.vue'
	import {
		checkVerifyCode,
		taxesAuthUrl
	} from '@/api/jinjian.js'
	
	import {
		sendVerifyCode
	} from '@/api/login'

	export default {
		components: {
			serveAgree
		},
		data() {
			return {

				serveAgreeVisible: false,
				onSearchIndex: 0,
				verifyCode: {
					verifyCodeTips: '获取验证码',
					countdown: 60,
				},
				code: '',
				userId: undefined,
				mobile: '',
				sign: undefined,
				remark: undefined,
				xz: false
			}
		},
		onLoad(event) {
			// 若不来自推荐，算作管理员的
			this.userId = event.ui ? event.ui : 1
			this.remark = event.ui ? null : '无推送'
			if (!localStorage.getItem('sign')) {
				localStorage.setItem('sign', this.userId + '_' + Date.now())
			}
			this.sign = localStorage.getItem('sign')
		},
		methods: {
			settime() {
				if (this.verifyCode.countdown === 1) {
					this.verifyCode.countdown = 60
					this.onSearchIndex = 0
					this.verifyCode.verifyCodeTips = "获取验证码"
					return
				} else {
					this.verifyCode.countdown--
				}
				this.verifyCode.verifyCodeTips = "重新获取(" + this.verifyCode.countdown + ")"
				setTimeout(() => {
					this.verifyCode.verifyCodeTips = "重新获取(" + this.verifyCode.countdown + ")"
					this.settime()
				}, 1000)
			},

			getCode() {
				if (!this.xz) {
					this.$modal.msgError('请勾选协议')
					return
				}
				if (this.mobile === '') {
					this.$modal.msgError('请输入手机号')
					return
				}
				var myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/
				if (!myreg.test(this.mobile)) {
					this.$modal.msgError('请输入正确的手机号')
					return
				}
				if (this.onSearchIndex !== 0) {
					return
				}
				this.onSearchIndex = 1
				this.settime()
				sendVerifyCode(this.mobile).then(res => {
					if (res.code == 200) {
						this.$modal.msgSuccess(res.msg)
					}
				})
			},

			submit() {
				if (!this.xz) {
					this.$modal.msgError('请勾选协议')
					return
				}
				if (this.mobile === '') {
					this.$modal.msgError('请输入手机号')
					return
				}
				var myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/
				if (!myreg.test(this.mobile)) {
					this.$modal.msgError('请输入正确手机号')
					return
				}
				if (this.code === '') {
					this.$modal.msgError("请输入验证码")
					return
				}
				checkVerifyCode({
					key: this.mobile,
					code: this.code
				}).then(res => {
					if (res.code == 200) {
						taxesAuthUrl({
							userId: this.userId,
							mobile: this.mobile,
							sign: this.sign,
							productId: 3,
							remark: this.remark
						}).then(res => {
							console.log('--res--', res)
							if (res.code == 200) {
								let url = encodeURIComponent(res.authUrl)
								this.$tab.navigateTo('/pages/qyns?id=' + res.queryId + '&url=' + url)
							} else {
								this.$modal.msgError(res.msg)
							}
						})
					} else {
						this.$modal.msgError(res.msg)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	@import "@/static/scss/names.scss";
</style>